using System.Linq;
using Core.Contracts.Interfaces;

namespace Core.Features
{
    using System;
    using Base;
    using Contracts.Enums;
    using Resources;

    
    public sealed class ReactorPerformance<T> : FeatureBase<object>
    {
        public ReactorPerformance(){}

        public ReactorPerformance(T value) 
            : base(value){ }
        /// <summary>
        /// Obtains the feature name
        /// </summary>
        public override string Name
        {
            get { return "Reactor performance"; }
        }
        /// <summary>
        /// Obtains the feature group
        /// </summary>
        public override FeatureGroupsEnum FeatureGroup{ get { return FeatureGroupsEnum.Engine; } }
        /// <summary>
        /// Obtains the feature type
        /// </summary>
        public override FeaturesEnum FeatureType { get { return FeaturesEnum.ReactorPerformance; } }
        /// <summary>
        /// Obtains or defines the feature unit
        /// </summary>
        public override string Unit { get { return Traduction.label_unit_RP; } }

        /// <summary>
        /// Determines if the feature value is rounded
        /// </summary>
        public override bool IsRounded
        {
            get { return true; }
        }

        public override void SetModifiedValue(IAgent agent, IRobot robot)
        {
            if (agent == null || robot == null) return;

            var temp = (double)Value *
                // Bonus from extensions
               (1 + agent.Extensions.SumModifiersValues(FeatureTypesEnum.Robot, this.FeatureType)) *
                // Bonus from Coreactors modules
               (1 + robot.Modules.SumModifiersValues(FeatureTypesEnum.Robot, this.FeatureType, ModuleGroupsEnum.Coreactors));

            ModifiedValue = IsRounded
                ? Math.Round(temp, 0, MidpointRounding.AwayFromZero)
                : Math.Round(temp, 2);
        }
    }
}